﻿using SuperX.Common;
using SuperX.ProjectCore;
using System;
using System.Text;
using System.Threading.Tasks;

namespace SuperX.ProjectManager
{
    /// <summary>
    /// 工程信息赋值
    /// </summary>
    public class ProjectMsg
    {
        private IProject _project;
        private DateTime _startTime;
        private string _projectName;
        private ITag _runTime;
        private int _deviceCount;
        private int _ioTagCount;
        private int _tagCount;

        public bool IsRun { get; set; }

        /// <summary>
        /// 工程运行
        /// </summary>
        /// <param name="project"></param>
        public void StartProject(IProject project)
        {
            _project = project;
            _projectName = _project.Name;
            //_runTime = _project.Objects["Tag.RunningTime"] as ITag;

            Task.Factory.StartNew(() =>
            {
                _project.Start();
                _startTime = project.StartTime;
                IsRun = true;
            });
        }

        public string GetString()
        {
            var project = ProjService.GetInstance().Project;
            var sb = new StringBuilder();
            //sb.AppendLine(string.Format("   工程名称：{0}", _projectName));
            //sb.AppendLine(string.Format("   开始时间：{0}", _startTime.ToString("yyyy-MM-dd hh:mm:ss")));
            //sb.AppendLine(string.Format("运行时间(S)：{0}", _runTime.Value));
            //sb.AppendLine(string.Format("   设备数量：{0}", _deviceCount));
            //sb.AppendLine(string.Format(" IO变量数量：{0}", _ioTagCount));

            //sb.AppendLine(string.Format("  当前时间:{0}", DateTime.Now.ToString("HH:mm:ss.fff")));

            //int i = 0, maxDisplayCount = 5;

            //sb.AppendLine(string.Format("   变量数量：{0}", _tagCount));

            return sb.ToString();
        }
    }
}